package ch.fusun.baron.basic.command.util;

import java.util.LinkedList;
import java.util.List;

import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.core.service.UserService;
import ch.fusun.baron.player.Dynasty;
import ch.fusun.baron.player.Player;
import ch.fusun.baron.player.api.Country;
import ch.fusun.baron.player.api.PlayerService;
import ch.fusun.baron.property.api.PropertyService;

/**
 * Implementation of the {@link PlayerUtil}
 */
public class PlayerUtilImpl implements PlayerUtil {

	@Inject
	private transient UserService userService;
	@Inject
	private transient PlayerService playerService;
	@Inject
	private transient PropertyService propertyService;

	@Override
	public List<Country> getCountriesForUser() {
		List<Country> result = new LinkedList<Country>();
		for (Player player : playerService.getPlayers(userService.getUser())) {
			result.addAll(propertyService.getAllOwnerships(player,
					Country.class));
		}
		return result;
	}

	@Override
	public Dynasty getDynasty() {
		return playerService.getDynasty(userService.getUser());
	}
}
